package cate.game.role.res.guild.po.treasurehouse.msg;

import cate.common.annotation.OperationSetter;
import cate.common.table.d.GDGuild;
import cate.common.table.d.GDOperation;
import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdGuild;
import easy.java.dev.note.NoteField;

@ClientMsg(title = "公会取出宝库 の 请求")
@OperationSetter(value = GDOperation.GUILD_TAKE_TREASURE_OUT)
public class GuildTakeTreasureOutReq implements MsgInput {
    @NoteField(value = "取出物品Id")
    public int tid;
    @NoteField(value = "取出物品数量")
    public int num;

    @Override
    public MsgConfig conf() {
        return MsgIdGuild.PULL_TREASURE_REQ;
    }

    @Override
    public void execute(GameBody game, ClientContext cc) {
        if (!cc.getRole().getRes().guild.checkGuild().ok()) {
            game.notice.message(cc.getRole(), 310450, "尚未加入协会");
            return;
        }
        if (cc.getRole().getRes().guild.getJoinDay() < GDGuild.TreasureHouse.JOIN_DAY_LIMIT) {
            game.notice.message(cc.getRole(), String.format("加入公会%d天后可以使用宝库", GDGuild.TreasureHouse.JOIN_DAY_LIMIT));
            return;
        }
        GameResult<Void> r = cc.getRole().getRes().guild.treasureHouse.takeTreasureOut(tid, num);
        if (!r.ok()) {
            game.notice.message(cc.getRole(), r);
        }
    }
}
